<?php

class gI18n extends gCoreObject
{
	private $pattern1 = "/ *([A-z0-9_-]{1,20}) *\: *([^\r\n]+) */"; # key | value
    private $pattern2 = "/>>> *([A-z0-9_-]{1,20}) *>>> *(.+) *<<</Us"; # >>> key >>> value <<< (for multiple strings)
	
	
	public function init()
	{
		
	}
	
	public function parseFile($filename)
	{
		if( !file_exists($filename))
		{
			throw new Exception('Cannot found language file', gError::FILE_NOT_FOUND);
		}
		$data = file_get_contents($filename);
		$tmp=array();
        $tmp2=array();
        $a=preg_match_all($this->pattern1,$data,$tmp);
        $b=preg_match_all($this->pattern2,$data,$tmp2);
        if( !$a && !$b){
        	return false;
        } else {
	        $_1=(isset($tmp[1]) && count($tmp[1])>0  )?array_combine(array_values($tmp[1]),array_values($tmp[2])):array();
	        $_2=(isset($tmp2[1]) && count($tmp2[1])>0  )?array_combine(array_values($tmp2[1]),array_values($tmp2[2])):array();
	        return array_merge($_1,$_2);
        }
	}
	
}